package com.chexiehui.jc.mvp.car;

import com.blankj.utilcode.util.StringUtils;
import com.chexiehui.jc.Constants;
import com.chexiehui.jc.base.ApiCallback;
import com.chexiehui.jc.base.BaseModel;
import com.chexiehui.jc.base.BasePresenter;
import com.chexiehui.jc.entity.CarPkListInfo;

import java.util.List;

/**
 * @Description 车型pk
 * @Auth SongJun
 * @Date 2020/05/21 00:18
 **/
public class CarBrandParameterComparePresenter extends BasePresenter<CarBrandParameterCompareCovenant.View, CarBrandParameterCompareCovenant.Stores>
        implements CarBrandParameterCompareCovenant.Presenter {

    public CarBrandParameterComparePresenter(CarBrandParameterCompareCovenant.View view) {
        attachView(view);
    }

    @Override
    public void getPkInfo() {
        if (StringUtils.isTrimEmpty(mvpView.getCarIds())) {
            mvpView.onGetPkInfoFailure(new BaseModel<>(Constants.PAGE_DATA_EMPTY, "没有找到任何数据"));
            return;
        }
        addSubscription(appStores.getPkInfo(mvpView.getCarIds()),
                new ApiCallback<BaseModel<List<CarPkListInfo>>>(mvpView) {
                    @Override
                    public void onSuccess(BaseModel<List<CarPkListInfo>> model) {
                        if (model.getResultCode() == 0) {
                            if (model.getData() != null && model.getData().size() > 0) {
                                mvpView.onGetPkInfoSuccess(model);
                            } else {
                                onFailure(Constants.PAGE_DATA_EMPTY, "没有找到任何数据");
                            }
                        } else {
                            onFailure(model.getResultCode(), model.getResultInfo());
                        }
                    }

                    @Override
                    public void onFailure(int code, String msg) {
                        mvpView.onGetPkInfoFailure(new BaseModel<>(code, msg));
                    }
                });
    }
}